/*
 * Copyright (c) 2015-2018 Sfkj Science And Technology Co.,Ltd.
 * All Rights Reserved.
 * This software is the confidential and proprietary information of
 * Sfkj Science And Technology Co.,Ltd.
 * ("Confidential Information").You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sfkj.
 */
package com.sfkj.walk.query.activity;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.annotations.QueryTransient;
import com.querydsl.core.types.Predicate;
import com.sfkj.walk.api.activity.ActivityMemberType;
import com.sfkj.walk.mongo.AbstractDocument;
import com.sfkj.walk.query.user.User;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.Indexed;

@Data
@EqualsAndHashCode(callSuper = true)
public class ActivityMember extends AbstractDocument {

    private static final long serialVersionUID = 8118041918500730458L;

    @Indexed
    private String activityId;
    @Indexed
    private String memberId;
    @Indexed
    private ActivityMemberType activityMemberType;

    @Transient
    @QueryTransient
    private User member;

    public static Predicate buildBy(String activityId, String memberId) {
        BooleanBuilder conditions = new BooleanBuilder();
        conditions.and(QActivityMember.activityMember.activityId.eq(activityId));
        conditions.and(QActivityMember.activityMember.memberId.eq(memberId));
        return conditions;
    }

    public static Predicate buildBy(String memberId, ActivityMemberType activityMemberType) {
        BooleanBuilder conditions = new BooleanBuilder();
        conditions.and(QActivityMember.activityMember.memberId.eq(memberId));
        conditions.and(QActivityMember.activityMember.activityMemberType.eq(activityMemberType));
        return conditions;
    }
}